package bb.lanxing.model.json;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import com.alibaba.fastjson.annotation.JSONField;
import com.umeng.analytics.pro.d;

import android.os.Parcel;
import android.os.Parcelable;

import bb.lanxing.activity.sport.SportActivity;
import bb.lanxing.model.database.ITrackPoint;
import bb.lanxing.model.database.RouteBook;
import bb.lanxing.model.database.WorkoutOther;

public class TrackSegment implements Parcelable, ITrackSegment {
    public static final Parcelable.Creator<TrackSegment> CREATOR = new Parcelable.Creator<TrackSegment>() {

        public TrackSegment createFromParcel(Parcel parcel) {
            return new TrackSegment(parcel);
        }

        public TrackSegment[] newArray(int i) {
            return new TrackSegment[i];
        }
    };
    private static final String COLUMNS_FOR_SEGMENT =
            "id, latitude, longitude, altitude, speed, cadence, heartrate, time";
    private int avg_cadence;
    private int avg_heartrate;
    private double avs;
    @JSONField(name = "best_rank")
    private BestWorkout bestWorkout;
    private int cadence_source;
    @JSONField(name = "count")
    private int challengeCount;
    private int comment_count;
    private double distance;
    private int duration;
    @JSONField(name = "segment_end")
    private int end;
    private int heart_source;
    private int id;
    private int is_like;
    @JSONField(name = "segment_loop_count")
    private int lapCount;
    @JSONField(name = "ulevel")
    private int level;
    @JSONField(name = "license_number_color")
    private String licenseNumberColor;
    @JSONField(name = "license_number_skin")
    private String licenseNumberSkin;
    private int like_count;
    private int locSource;
    private RouteBook routeBook;
    @JSONField(name = "lushu_distance")
    private double lushuDistance;
    @JSONField(name = SportActivity.EXTRA_LUSHU_ID)
    private long lushuId;
    @JSONField(name = "lushu_title")
    private String lushuTitle;
    private double max_altitude;
    private int max_cadence;
    private int max_heartrate;
    private double max_speed;

    private String medalSmall;
    @JSONField(name = "license_number")
    private String plateNum;

    private List<ITrackPoint> pointList;
    @JSONField(name = "pro_name")
    private String proName;
    private int rank;
    private double similarity;
    private int sport;
    @JSONField(name = "segment_start")
    private int start;
    @JSONField(name = d.p)
    private long startTime;
    @JSONField(name = "pic_url")
    private String userAvatar;
    @JSONField(name = "medal_small")
    private List<UserAvatarMedal> userAvatarMedals;
    @JSONField(name = "user_id")
    private long userId;
    @JSONField(name = "user_name")
    private String userName;
    private WorkoutOther workout;
    @JSONField(name = "workout_id")
    private long workoutId;
    private List<WorkoutLap> workoutLaps;
    @JSONField(name = "uuid")
    private String workoutUuid;
    private String workout_title;

    public TrackSegment() {
        this.sport = -1;
    }

    protected TrackSegment(Parcel parcel) {
        this.sport = -1;
        this.id = parcel.readInt();
        this.workoutId = parcel.readLong();
        this.workoutUuid = parcel.readString();
        this.userId = parcel.readLong();
        this.userAvatar = parcel.readString();
        this.userName = parcel.readString();
        this.level = parcel.readInt();
        this.lushuId = parcel.readLong();
        this.lushuTitle = parcel.readString();
        this.lushuDistance = parcel.readDouble();
        this.start = parcel.readInt();
        this.end = parcel.readInt();
        this.avs = parcel.readDouble();
        this.duration = parcel.readInt();
        this.similarity = parcel.readDouble();
        this.rank = parcel.readInt();
        this.distance = parcel.readDouble();
        this.challengeCount = parcel.readInt();
        this.bestWorkout = (BestWorkout) parcel.readParcelable(BestWorkout.class.getClassLoader());
        this.startTime = parcel.readLong();
        this.workout_title = parcel.readString();
        this.heart_source = parcel.readInt();
        this.cadence_source = parcel.readInt();
        this.max_cadence = parcel.readInt();
        this.avg_cadence = parcel.readInt();
        this.max_heartrate = parcel.readInt();
        this.avg_heartrate = parcel.readInt();
        this.locSource = parcel.readInt();
        this.max_altitude = parcel.readDouble();
        this.max_speed = parcel.readDouble();
        this.comment_count = parcel.readInt();
        this.like_count = parcel.readInt();
        this.is_like = parcel.readInt();
        this.sport = parcel.readInt();
        ArrayList arrayList = new ArrayList();
        this.pointList = arrayList;
        parcel.readList(arrayList, ITrackPoint.class.getClassLoader());
        this.medalSmall = parcel.readString();
        this.userAvatarMedals = parcel.createTypedArrayList(UserAvatarMedal.CREATOR);
        this.plateNum = parcel.readString();
        this.proName = parcel.readString();
        this.lapCount = parcel.readInt();
        this.workoutLaps = parcel.createTypedArrayList(WorkoutLap.CREATOR);
        this.workout = (WorkoutOther) parcel.readParcelable(WorkoutOther.class.getClassLoader());
        this.routeBook = (RouteBook) parcel.readParcelable(RouteBook.class.getClassLoader());
        this.licenseNumberColor = parcel.readString();
        this.licenseNumberSkin = parcel.readString();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public List<ITrackPoint> querySegmentPoint() {
        WorkoutOther workout = getWorkout();
        if (workout.getId() == null) {
            return null;
        }
        LinkedList linkedList = new LinkedList();
        // Cursor rawQuery = SugarRecord.getSugarDb().getDB().rawQuery("SELECT id, latitude, longitude, altitude, speed,
        // cadence, heartrate, time FROM trackpoint_other WHERE workout_id = ? order by time asc limit ?,?", new
        // String[]{String.valueOf(workout.getId()), String.valueOf(this.start), String.valueOf((this.end - this.start)
        // + 1)});
        // while (rawQuery.moveToNext()) {
        // TrackPointOther trackPointOther = new TrackPointOther();
        // trackPointOther.setId(Long.valueOf(rawQuery.getLong(0)));
        // trackPointOther.setLatitude(rawQuery.getDouble(1));
        // trackPointOther.setLongitude(rawQuery.getDouble(2));
        // trackPointOther.setAltitude(rawQuery.getDouble(3));
        // trackPointOther.setSpeed(rawQuery.getDouble(4));
        // trackPointOther.setCadence(rawQuery.getInt(5));
        // trackPointOther.setHeartrate(rawQuery.getInt(6));
        // trackPointOther.setTime(rawQuery.getLong(7));
        // if (CommonUtil.isPointValid(trackPointOther.getLatitude(), trackPointOther.getLongitude())) {
        // linkedList.add(trackPointOther);
        // }
        // }
        // rawQuery.close();
        return linkedList;
    }

    public List<ITrackPoint> getPointList() {
        return this.pointList;
    }

    public void setPointList(List<ITrackPoint> list) {
        this.pointList = list;
    }

    public int getId() {
        return this.id;
    }

    public void setId(int i) {
        this.id = i;
    }

    public long getWorkoutId() {
        return this.workoutId;
    }

    public void setWorkoutId(long j) {
        this.workoutId = j;
    }

    public String getWorkoutUuid() {
        return this.workoutUuid;
    }

    public void setWorkoutUuid(String str) {
        this.workoutUuid = str;
    }

    public long getUserId() {
        return this.userId;
    }

    public void setUserId(long j) {
        this.userId = j;
    }

    public String getUserAvatar() {
        return this.userAvatar;
    }

    public void setUserAvatar(String str) {
        this.userAvatar = str;
    }

    public int getLevel() {
        return this.level;
    }

    public void setLevel(int i) {
        this.level = i;
    }

    public List<UserAvatarMedal> getUserAvatarMedals() {
        return this.userAvatarMedals;
    }

    public void setUserAvatarMedals(List<UserAvatarMedal> list) {
        this.userAvatarMedals = list;
        if (list != null) {
            String str = "";
            for (int i = 0; i < list.size(); i++) {
                str = i == list.size() - 1 ? str + list.get(i).getUrl() : str + list.get(i).getUrl() + ";";
            }
            setMedalSmall(str);
            return;
        }
        setMedalSmall(null);
    }

    public String getMedalSmall() {
        return this.medalSmall;
    }

    public void setMedalSmall(String str) {
        this.medalSmall = str;
    }

    public String getPlateNum() {
        return this.plateNum;
    }

    public void setPlateNum(String str) {
        this.plateNum = str;
    }

    public String getProName() {
        return this.proName;
    }

    public void setProName(String str) {
        this.proName = str;
    }

    public String getUserName() {
        return this.userName;
    }

    public void setUserName(String str) {
        this.userName = str;
    }

    public long getLushuId() {
        return this.lushuId;
    }

    public void setLushuId(long j) {
        this.lushuId = j;
    }

    public int getStart() {
        return this.start;
    }

    public void setStart(int i) {
        this.start = i;
    }

    public int getEnd() {
        return this.end;
    }

    public void setEnd(int i) {
        this.end = i;
    }

    public double getAvs() {
        return this.avs;
    }

    public void setAvs(double d) {
        this.avs = d;
    }

    @Override
    public int getDuration() {
        return this.duration;
    }

    public void setDuration(int i) {
        this.duration = i;
    }

    public double getSimilarity() {
        return this.similarity;
    }

    public void setSimilarity(double d) {
        this.similarity = d;
    }

    public int getRank() {
        return this.rank;
    }

    public void setRank(int i) {
        this.rank = i;
    }

    @Override
    public double getDistance() {
        return this.distance;
    }

    public void setDistance(double d) {
        this.distance = d;
    }

    public int getChallengeCount() {
        return this.challengeCount;
    }

    public void setChallengeCount(int i) {
        this.challengeCount = i;
    }

    public String getLushuTitle() {
        return this.lushuTitle;
    }

    public void setLushuTitle(String str) {
        this.lushuTitle = str;
    }

    public double getLushuDistance() {
        return this.lushuDistance;
    }

    public void setLushuDistance(double d) {
        this.lushuDistance = d;
    }

    public String getWorkout_title() {
        return this.workout_title;
    }

    public void setWorkout_title(String str) {
        this.workout_title = str;
    }

    public int getHeart_source() {
        return this.heart_source;
    }

    public void setHeart_source(int i) {
        this.heart_source = i;
    }

    public int getCadence_source() {
        return this.cadence_source;
    }

    public void setCadence_source(int i) {
        this.cadence_source = i;
    }

    public int getMax_cadence() {
        return this.max_cadence;
    }

    public void setMax_cadence(int i) {
        this.max_cadence = i;
    }

    public int getAvg_cadence() {
        return this.avg_cadence;
    }

    public void setAvg_cadence(int i) {
        this.avg_cadence = i;
    }

    public int getMax_heartrate() {
        return this.max_heartrate;
    }

    public void setMax_heartrate(int i) {
        this.max_heartrate = i;
    }

    public int getAvg_heartrate() {
        return this.avg_heartrate;
    }

    public void setAvg_heartrate(int i) {
        this.avg_heartrate = i;
    }

    public double getMax_altitude() {
        return this.max_altitude;
    }

    public void setMax_altitude(double d) {
        this.max_altitude = d;
    }

    public double getMax_speed() {
        return this.max_speed;
    }

    public void setMax_speed(double d) {
        this.max_speed = d;
    }

    public int getComment_count() {
        return this.comment_count;
    }

    public void setComment_count(int i) {
        this.comment_count = i;
    }

    public int getLike_count() {
        return this.like_count;
    }

    public void setLike_count(int i) {
        this.like_count = i;
    }

    public int getIs_like() {
        return this.is_like;
    }

    public void setIs_like(int i) {
        this.is_like = i;
    }

    public int getLocSource() {
        return this.locSource;
    }

    public void setLocSource(int i) {
        this.locSource = i;
    }

    public int getSport() {
        return this.sport;
    }

    public void setSport(int i) {
        this.sport = i;
    }

    public long getStartTime() {
        return this.startTime;
    }

    public void setStartTime(long j) {
        this.startTime = j;
    }

    public int getLapCount() {
        return this.lapCount;
    }

    public void setLapCount(int i) {
        this.lapCount = i;
    }

    public List<WorkoutLap> getWorkoutLaps() {
        return this.workoutLaps;
    }

    public void setWorkoutLaps(List<WorkoutLap> list) {
        this.workoutLaps = list;
    }

    public BestWorkout getBestWorkout() {
        return this.bestWorkout;
    }

    public void setBestWorkout(BestWorkout bestWorkout) {
        this.bestWorkout = bestWorkout;
    }

    public String getLicenseNumberSkin() {
        return this.licenseNumberSkin;
    }

    public void setLicenseNumberSkin(String str) {
        this.licenseNumberSkin = str;
    }

    public String getLicenseNumberColor() {
        return this.licenseNumberColor;
    }

    public void setLicenseNumberColor(String str) {
        this.licenseNumberColor = str;
    }

    public WorkoutOther getWorkout() {
        if (this.workout == null) {
            WorkoutOther workoutOther = new WorkoutOther();
            this.workout = workoutOther;
            workoutOther.setServerId(this.workoutId);
            this.workout.setTitle(this.workout_title);
            this.workout.setHeartSource(this.heart_source);
            this.workout.setCadenceSource(this.cadence_source);
            this.workout.setMaxCadence(this.max_cadence);
            this.workout.setAvgCadence(this.avg_cadence);
            this.workout.setMaxHeartrate(this.max_heartrate);
            this.workout.setAvgHeartrate(this.avg_heartrate);
            this.workout.setMaxSpeed(this.max_speed);
            this.workout.setMaxAltitude(this.max_altitude);
            this.workout.setCommentCount(this.comment_count);
            this.workout.setLocSource(this.locSource);
            this.workout.setLikeCount(this.like_count);
            this.workout.setIsLike(this.is_like);
            this.workout.setSport(3);
            this.workout.setMatchedSegments(1);
            this.workout.setSport(this.sport);
            this.workout.setAvgSpeed(this.avs);
            this.workout.setDistance(this.distance);
            this.workout.setDuration(this.duration);
            this.workout.setStartTime(this.startTime);
            this.workout.setEndTime(this.startTime + this.duration);
            this.workout.setUuid(this.workoutUuid);
        }
        return this.workout;
    }

    public void setWorkout(WorkoutOther workoutOther) {
        this.workout = workoutOther;
    }

    public RouteBook getLushu() {
        return this.routeBook;
    }

    public void setLushu(RouteBook routeBook) {
        this.routeBook = routeBook;
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeInt(this.id);
        parcel.writeLong(this.workoutId);
        parcel.writeString(this.workoutUuid);
        parcel.writeLong(this.userId);
        parcel.writeString(this.userAvatar);
        parcel.writeString(this.userName);
        parcel.writeInt(this.level);
        parcel.writeLong(this.lushuId);
        parcel.writeString(this.lushuTitle);
        parcel.writeDouble(this.lushuDistance);
        parcel.writeInt(this.start);
        parcel.writeInt(this.end);
        parcel.writeDouble(this.avs);
        parcel.writeInt(this.duration);
        parcel.writeDouble(this.similarity);
        parcel.writeInt(this.rank);
        parcel.writeDouble(this.distance);
        parcel.writeInt(this.challengeCount);
        parcel.writeParcelable(this.bestWorkout, i);
        parcel.writeLong(this.startTime);
        parcel.writeString(this.workout_title);
        parcel.writeInt(this.heart_source);
        parcel.writeInt(this.cadence_source);
        parcel.writeInt(this.max_cadence);
        parcel.writeInt(this.avg_cadence);
        parcel.writeInt(this.max_heartrate);
        parcel.writeInt(this.avg_heartrate);
        parcel.writeInt(this.locSource);
        parcel.writeDouble(this.max_altitude);
        parcel.writeDouble(this.max_speed);
        parcel.writeInt(this.comment_count);
        parcel.writeInt(this.like_count);
        parcel.writeInt(this.is_like);
        parcel.writeInt(this.sport);
        parcel.writeList(this.pointList);
        parcel.writeString(this.medalSmall);
        parcel.writeTypedList(this.userAvatarMedals);
        parcel.writeString(this.plateNum);
        parcel.writeString(this.proName);
        parcel.writeInt(this.lapCount);
        parcel.writeTypedList(this.workoutLaps);
        parcel.writeParcelable(this.workout, i);
        parcel.writeParcelable(this.routeBook, i);
        parcel.writeString(this.licenseNumberColor);
        parcel.writeString(this.licenseNumberSkin);
    }

    public static class BestWorkout implements Parcelable {
        public static final Parcelable.Creator<BestWorkout> CREATOR = new Parcelable.Creator<BestWorkout>() {

            public BestWorkout createFromParcel(Parcel parcel) {
                return new BestWorkout(parcel);
            }

            public BestWorkout[] newArray(int i) {
                return new BestWorkout[i];
            }
        };
        private long duration;
        private int rank;
        @JSONField(name = "workout_id")
        private long workoutId;

        public BestWorkout() {
        }

        protected BestWorkout(Parcel parcel) {
            this.workoutId = parcel.readLong();
            this.rank = parcel.readInt();
            this.duration = parcel.readLong();
        }

        @Override
        public int describeContents() {
            return 0;
        }

        public long getWorkoutId() {
            return this.workoutId;
        }

        public void setWorkoutId(long j) {
            this.workoutId = j;
        }

        public int getRank() {
            return this.rank;
        }

        public void setRank(int i) {
            this.rank = i;
        }

        public long getDuration() {
            return this.duration;
        }

        public void setDuration(long j) {
            this.duration = j;
        }

        @Override
        public void writeToParcel(Parcel parcel, int i) {
            parcel.writeLong(this.workoutId);
            parcel.writeInt(this.rank);
            parcel.writeLong(this.duration);
        }
    }
}
